/**
 * \file    transaction.cpp
 * \brief   Helps to build the action table from a generator.
 * \author  Jérôme LAURENS
 * \version 0.1
 * \date    November 20, 2014
 *
 * Reads a LALR(1) grammar, generates a parser based on a template file.
 * This is based on lemon parser generator, but has strongly been
 * revisited.
 *
 */

#include "transaction.h"
#include "description.h"
#include "state.h"

/* Add a new action to the current transaction set.
**
** This routine is called once for each lookahead for a particular
** state.
*/
void TransactionSet::add_transaction(ActionRef const & action, SymbolIndex lookahead, ActionCode code) {
    DEBUG_MESSAGE("add_transaction: %s, lookahead: %s, code: %lu",Description()(action).c_str(),action->lookahead()->name().c_str(),code);
    transactions_m.emplace_back(lookahead,code);
    if (max_lookahead_m<=lookahead) max_lookahead_m = lookahead+1;// allways lookahead<max_lookahead_m
    if (min_lookahead()>lookahead) {
        min_transaction_m = transactions_m.back();// allways lookahead≥min_lookahead_m
    }
}

bool operator== (TransactionSet const & lhs, TransactionSet const & rhs) {
    return lhs.transactions()==rhs.transactions();
}
